/*
 * @lc app=leetcode.cn id=404 lang=javascript
 *
 * [404] 左叶子之和
 */

// @lc code=start
/**
 * Definition for a binary tree node.
 * function TreeNode(val) {
 *     this.val = val;
 *     this.left = this.right = null;
 * }
 */
/**
 * @param {TreeNode} root
 * @return {number}
 */
var sumOfLeftLeaves = function (root) {
    let queue = [root]
    let sum=0
    while(queue.length){
        let temp=queue.shift()
        if(!temp)continue
        if (temp.left) {
            if (!temp.left.left && !temp.left.right) { sum += temp.left.val }
        }
        queue.push(temp.left)
        queue.push(temp.right)
    }
    return sum
};//BFS
// @lc code=end

var sumOfLeftLeaves = function (root) {
    let sum = 0
    let dfs = function (root) {
        if (!root) { return }
        if (root.left) {
            if (!root.left.left && !root.left.right) { sum += root.left.val }
        }
        dfs(root.left)
        dfs(root.right)
    }
    dfs(root)
    return sum//dfs
};